package com.bj58.disconf.web.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bj58.sfft.utility.dao.basedao.DAOBase;
import com.bj58.sfft.utility.dao.basedao.DAOHelper;

/**
 * 
 * 
 * 
 * @author wangyazhou
 * @version 1.0
 * @date  2016年4月20日 下午7:57:28
 * @see 
 * @since
 */
public class DBHelper {

    private static final Logger logger = LoggerFactory.getLogger(DBHelper.class);

    private DAOHelper daoHelper = null;
    private static volatile DBHelper instance = null;

    private DBHelper() {
    }

    public DAOHelper getDao() {
        return daoHelper;
    }

    public static DBHelper getInstance() {
        if (instance == null) {
            synchronized (DBHelper.class) {
                if (instance != null) {
                    return instance;
                }
                instance = new DBHelper();
                try {
                    //                    String dbpath = WF.getConfigFolder() + File.separator + WF.getNamespace() + File.separator + "db.properties";
                    String dbpath = "E:\\opt\\wf\\disconfig\\db.properties";
                    logger.info(dbpath);
                    instance.daoHelper = DAOBase.createIntrance(dbpath);
                    logger.info("init dao success");
                } catch (Exception e) {
                    e.printStackTrace();
                    instance = null;
                    logger.error("DBHelper init error", e);
                }
            }
        }
        return instance;
    }

}
